package com.weilive.api.gate.json.handler;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.weilive.api.ServerErrors;
import com.weilive.api.gate.json.protocol.CSA_GetLiveByVjTypeId;
import com.weilive.api.gate.json.protocol.CSQ_GetLiveByVjTypeId;
import com.weilive.api.gate.json.protocol.RoomInfoModel;
import com.weilive.api.service.DataPool;
import com.weilive.core.protocol.json.JsonRequest;
import com.weilive.core.protocol.json.JsonRequestHandler;
import com.weilive.core.protocol.json.JsonResponse;

@Service
public class CSQ_GetLiveByVjTypeId_JsonHandler extends JsonRequestHandler {

	@Autowired
	private DataPool dataPool;

	public Class<?> getRequestType() {
		return CSQ_GetLiveByVjTypeId.class;
	}

	public Class<?> getResponseType() {
		return CSA_GetLiveByVjTypeId.class;
	}

	public JsonResponse handleRequest(JsonRequest request) throws Exception {
		CSQ_GetLiveByVjTypeId params = (CSQ_GetLiveByVjTypeId) request.getData();
		if (params.getAnchorTypeId() == null) {
			return createErrorResponse(ServerErrors.PARAM_INVALID);
		}
		CSA_GetLiveByVjTypeId response = new CSA_GetLiveByVjTypeId();

		List<RoomInfoModel> liveList = dataPool.getLiveByVjTypeList(params.getAnchorTypeId());

		if (liveList == null) {
			response.setLiveList(new ArrayList<RoomInfoModel>());
		} else {
			response.setLiveList(liveList);
		}
		return JsonResponse.create(response);
	}

}
